﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Data;
using DotNet.Model;
using DotNet.Common;
namespace DotNet.Business
{
    /// <summary>
    /// 缓存  IList<Contact> GetModel() "Contact_1"
    /// </summary>
    public class ContactBll
    {
        ContactDal ConDal = new ContactDal();
        #region 是否存在该记录
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int contactId)
        {
            return ConDal.Exists(contactId);
        }
        #endregion

        #region 获得相关联系列表
        /// <summary>
        /// 获得相关联系列表
        /// </summary>
        /// <returns></returns>
        public IList<Contact> GetModel()
        {
            string CKey = "Contact_1";
            if (!CacheUtil.IsExist(CKey))
            {
                CacheUtil.Insert(CKey, ConDal.GetModel(), 10 * 24 * 60 * 60);
            }
            return CacheUtil.Read(CKey) as IList<Contact>;
        }
        #endregion

        #region 根据相关联系号查询实体
        /// <summary>
        /// 根据相关联系号查询实体
        /// </summary>
        /// <param name="contactId"></param>
        /// <returns></returns>
        public Contact GetModel(int contactId)
        {
            return ConDal.GetModel(contactId);
        }
        #endregion

        #region 修改相关联系信息
        /// <summary>
        /// 修改相关联系信息
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        public bool Update(Contact contact)
        {
            CacheUtil.Remove("Contact_1");
            return ConDal.Update(contact);
        }
        #endregion

        #region 删除相关联系根据相关联系号
        /// <summary>
        /// 删除相关联系根据相关联系号
        /// </summary>
        /// <param name="contactId"></param>
        /// <returns></returns>
        public bool Delete(int contactId)
        {
            CacheUtil.Remove("Contact_1");
            return ConDal.Delete(contactId);
        }
        #endregion

        #region 添加相关联系
        /// <summary>
        /// 添加相关联系
        /// </summary>
        /// <param name="Contact"></param>
        /// <returns></returns>
        public bool Insert(Contact contact)
        {
            CacheUtil.Remove("Contact_1");
            return ConDal.Insert(contact);
        }
        #endregion
    }
}
